home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14057 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help trapping stdout from Unix system() c
  5. Date: 11 Apr 1996 16:20:38 GMT
  6. Organization: OpenVision
  7. Message-ID: <4kjbgm$7fm@spanky.pls.ov.com>
  8. References: <DpnGsD.Mo2@ul.ie>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article Mo2@ul.ie, vincent.walsh@ul.ie (Vincent Walsh) writes:
  13. >Hi All,
  14. >I have a problem and would appreciate is someone could help me!
  15. >
  16. >Within a C program I call another C program and I want to trap the output 
  17. >of the second C program into a buffer. I tried using fopen, etc.. and 
  18. >system() calls, but to no avail.
  19. >I also tried using popen to call the second C program and this trapped the
  20. >stdout into a buffer, but not stderr. Which means my buffer will tell me 
  21. >the results if the second program works, but my buffer is empty if the 
  22. >second program outputs to stderr!!
  23. >
  24. >I'm confused
  25. >
  26. >Thanks
  27. >Vincent Walsh
  28. >vincent.walsh@ul.ie
  29. >
  30.  
  31.  
  32. This request really belongs in comp.unix.programmer, but you should try:
  33.  
  34. popen("your_command 2>&1", "r");
  35.  
  36. The "2>&1" causes the shell that executes your program to direct stderr into
  37. stdout.
  38.         Fletcher.Glenn@ov.com
  39.  
  40.